package com.yidu.qianfeng.track_ying;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yidu.qianfeng.common.bean.track.TrackWaybillCondition;
import com.yidu.qianfeng.common.bean.transport.TrackWaybill;
import com.yidu.qianfeng.common.util.LayuiJsonWrap;
import com.yidu.qianfeng.service.TrackWaybillService;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @Author: 银宇豪
 * @Description: 跟踪记录视图控制器，查询
 * @Date Created in 9:40 2021/4/21
 * @since 1.0
 */
public class TrackYingController {

    //注入跟踪业务
    @Resource(name = "trackWaybillServiceImpl")
    private TrackWaybillService trackWaybillService;

    /**
     * 查询跟踪记录分页
     * @param page 当前页
     * @param limit 显示条目数
     * @return layui包装实体
     */
    @RequestMapping("/queryTrackLimitLayui")
    public @ResponseBody
    LayuiJsonWrap queryTrackLimitLayui(@Param("page") int page, @Param("limit") int limit){

        return trackWaybillService.queryTrackLimitLayui(page,limit);
    }

    /**
     * 查询跟踪记录根据id
     * @param trackId 跟踪记录id
     * @return 跟踪记录实体
     */
    @RequestMapping("/queryOneTrackById")
    public @ResponseBody
    TrackWaybill queryOneTrackById(String trackId){

        return trackWaybillService.queryOneTrackById(trackId);
    }

    /**
     * 查询跟踪记录根据条件
     * @param trackWaybillCondition 查询条件包装类
     * @return layui包装实体
     */
    @RequestMapping("/queryTrackByCondition")
    public @ResponseBody LayuiJsonWrap queryTrackByConditionLayui(@RequestParam("trackWaybillCondition") String trackWaybillCondition){
        TrackWaybillCondition trackCondition = null;
        try {
            //json字符串jackson转换为condition对象
            trackCondition = new ObjectMapper().readValue(trackWaybillCondition, TrackWaybillCondition.class);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        return trackWaybillService.queryTrackByConditionLayui(trackCondition);
    }

}
